<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>8.搜索computed</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="app">
            <input type="search" v-model="search"><br><br>
            <li v-for="item in newstudent" :key="item.id">
                {{item.name}}----{{item.age}} --- {{item.gender}}
            </li>
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        new Vue({
            el:"#app",
            data:{
                student:[
                    {id:1,name:"二蛋",age:18,gender:"男"},
                    {id:2,name:"三楞",age:18,gender:"男"},
                    {id:3,name:"四柱",age:18,gender:"男"},
                    {id:4,name:"五哥",age:18,gender:"男"},
                    {id:5,name:"六叔",age:18,gender:"男"}
                ],
                search:""
            },
            computed:{
                newstudent(){
                    return this.student.filter(item=>item.name.indexOf(this.search)!==-1)
                }
            }
        })
        
        
    </script>
</html>